home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _0DF95BA5C5FA4419B514265968F0F56B < prev    next >
Encoding:
Text File  |  2004-01-06  |  6.4 KB  |  264 lines

  1. --#Script.ReloadScript("scripts/default/entities/weapons/smokerocket.lua")
  2. SmokeRocket = {
  3.     type = "Projectile",
  4.     tid_cloud = System:LoadTexture("textures/cloud.jpg"),
  5.     decal_tid = System:LoadTexture("textures/explo_decal.tga"),
  6.  
  7.     lockTarget = nil,
  8.     smokeTime = 120,
  9.     
  10.     Param = {
  11.         mass = 1,
  12.         size = 0.05,
  13.         heading = {},
  14.         initial_velocity = 60,
  15.         k_air_resistance = 0,
  16.         acc_thrust = 0,
  17.         acc_lift = 0,
  18.         surface_idx = 0,
  19.         gravity = {x=0, y=0, z=4*-9.8 },
  20.         collider_to_ignore = nil,
  21.     },
  22.     
  23.     ExplosionParams = {
  24.         pos = {},
  25.         damage = 160,
  26.         rmin = 0.8,
  27.         rmax = 10.5,
  28.         radius = 10,
  29.         impulsive_pressure = 5,
  30.         shooter = nil,
  31.         weapon = nil,
  32.     },
  33.     
  34.     FlyingSmoke = {
  35.         focus = 0,
  36.         start_color = {0.737,0.286,0.725},
  37.         end_color = {0.737,0.286,0.725},
  38.         speed = 0.2,
  39.         count = 1,
  40.         size = 0.2, size_speed=1.2,
  41.         lifetime=1,
  42.         frames=1,
  43.         tid = System:LoadTexture("textures/clouda.dds"),
  44.     },
  45.  
  46.     SignalSmoke = {
  47.         focus = 3,
  48.         start_color = {0.737,0.286,0.725},
  49.         end_color = {0.737,0.286,0.725},
  50.         speed = 1.75,
  51.         count = 2,
  52.         size = 0.005, size_speed=0.1,
  53.         lifetime=15,
  54.         gravity = {x= 0.3,y= 0,z= 0},
  55.         rotation = {x= 0,y = 0,z = 3},
  56.         frames=1,
  57.         tid = System:LoadTexture("textures/clouda.dds"),
  58.     },
  59.     
  60.     RocketEngineLoop = nil,
  61.  
  62.     ExplosionTimer = 0,    
  63.     bPhysicalized = nil,
  64.     was_underwater=nil,
  65.     water_normal={x=0,y=0,z=1}        
  66. }
  67.  
  68. function SmokeRocket:Server_OnInit()
  69.     self:RegisterState("Flying");
  70.     self:RegisterState("Exploding");
  71.     self:GotoState( "Flying" );
  72.  
  73.     self:SetPos({x=-1000,y=-1000,z=-1000});
  74.     self.part_time = 0;
  75.     if(self.bPhysicalized==nil)then
  76.         self:CreateParticlePhys( 2, 10 );
  77.         self.bPhysicalized=1;
  78.     end
  79. end
  80.  
  81. function SmokeRocket:Client_OnInit()
  82.  
  83.     self.RocketEngineLoop = Sound:Load3DSound("Sounds/building/smoke.wav",SOUND_DUPLICATE);
  84.  
  85.     self:RegisterState("Flying");
  86.     self:RegisterState("Exploding");
  87.     self:GotoState( "Flying" );
  88.  
  89.     self:LoadObject( "objects/weapons/Rockets/rocket.cgf",0,0.5);
  90.     --self.LoadObject( "objects/explosion/explosion.cgf", 1, 0.5);
  91.     self.part_time = 0;
  92.     if(self.bPhysicalized==nil)then
  93.         self:CreateParticlePhys( 2, 10 );
  94.         self.bPhysicalized=1;
  95.     end
  96. end
  97.  
  98. function SmokeRocket:Server_Flying_OnUpdate(dt)
  99.  
  100.     if(self.lockTarget~=nil) then
  101.         --FIXME hack because the better way to see if entity is still valid should be implemented soon by Alberto
  102.         if( self.lockTarget.GetPos == nil ) then
  103.             self.lockTarget=nil;
  104.         else
  105.             self:DoHam(self.lockTarget:GetPos());
  106.         end    
  107.     end    
  108.  
  109.     --System.LogToConsole("--> Rocket Snd ID: "..self.RocketEngineLoop);
  110.  
  111.     local status=GetParticleCollisionStatus(self);
  112.     local pos=self:GetPos();
  113.     
  114.     if (status ~= nil) then
  115.         --set a member variable to pass to ExecuteMaterial in OnCollision
  116.         local material=status.target_material;
  117.         if(IsMaterialUnpierceble(status.target_material))then
  118.             self["status"]=status;
  119.             self:GotoState("Exploding");
  120.         else
  121.             ExecuteMaterial(pos,status.normal,material.projectile_hit,1)
  122.         end
  123.     elseif (System:IsValidMapPos(pos) ~= 1) then
  124.         self:GotoState("Exploding");
  125.         --System.RemoveEntity(self.id);
  126.     end
  127.     
  128.     if(Materials["mat_water"] and Materials["mat_water"].projectile_hit)then
  129.         if(self.was_underwater==nil)then
  130.             if(Game:IsPointInWater(pos)) then
  131.                 System:LogToConsole("UNDERWATER");
  132.                 self.was_underwater=1;
  133.                 ExecuteMaterial(pos, self.water_normal, Materials.mat_water.projectile_hit, 1 )
  134.             end
  135.         end
  136.     end
  137. end
  138.  
  139. function SmokeRocket:Server_Exploding_OnUpdate(dt)
  140.  
  141.     self.smokeTime = self.smokeTime - dt;
  142.     if( self.smokeTime<0 ) then
  143.         Server:RemoveEntity( self.id );
  144.         
  145.     end    
  146.  
  147. end
  148.  
  149. function SmokeRocket:Client_Flying_OnUpdate(dt)
  150.     self.part_time = self.part_time + dt*2;
  151.  
  152.     if (self.part_time>0.03) then        
  153.         self:DrawObject(0,1);
  154.         local pos = self:GetPos();
  155.         Particle:CreateParticle( pos,{x=0,y=0,z=0},self.FlyingSmoke );
  156.         self.part_time=0;
  157.     end
  158.  
  159.  
  160.     -- HACK: Marco, why do I have to call PlaySound all the time, no looping ?
  161.     --     Alberto, why doesn't self.PlaySound() move the sound and I have to do that manually ?
  162. --    if (Sound.IsPlaying(self.RocketEngineLoop) == nil) then
  163. --        self.PlaySound(self.RocketEngineLoop);
  164. --    end
  165. --    Sound.SetSoundPosition(self.RocketEngineLoop, self.GetPos());
  166.  
  167.  
  168.  
  169. end
  170.  
  171. function SmokeRocket:Client_Exploding_OnUpdate(dt)
  172.  
  173.     local pos = self.GetPos();
  174.     Particle:CreateParticle( pos,{x=0,y=0,z=1},self.SignalSmoke );
  175.  
  176.     self.part_time = self.part_time + dt*2;
  177.  
  178.     self:SetStatObjScale((System:GetCurrTime() - self.ExplosionTimer) * 35);
  179.  
  180.     -- vPos, fRadius, DiffR, DiffG, DiffB, DiffA, SpecR, SpecG, SpecB, SpecA, fLifeTime
  181.  
  182.  
  183.     if (Sound:IsPlaying(self.RocketEngineLoop)) then
  184.         Sound:SetSoundPosition(self.RocketEngineLoop, pos);
  185.     end    
  186.     
  187. --self.RocketEngineLoop=-1;
  188. end
  189.  
  190. function SmokeRocket:Launch( weapon, shooter, pos, angles, dir, target )
  191.     self.Param.heading = dir;
  192.     self.Param.collider_to_ignore = shooter;
  193.     self:SetPhysicParams( PHYSICPARAM_PARTICLE, self.Param );
  194.     self:SetPos( pos );
  195.     self:SetAngles( angles );
  196.     self.ExplosionParams.shooter = shooter;
  197.     self.ExplosionParams.weapon = weapon;
  198.     
  199.     self.lockTarget = target;
  200.  
  201.     if(self.lockTarget~=nil) then
  202.         self:ResetHam( );
  203.     end    
  204.     
  205.  
  206.     
  207.     if (Game:IsClient()) then
  208.         self:DrawObject( 0, 1 );
  209.     end
  210.  
  211.     if (self.RocketEngineLoop) then
  212.         Sound:SetSoundLoop(self.RocketEngineLoop, 1);
  213.         Sound:SetMinMaxDistance(self.RocketEngineLoop, 3, 100000);
  214.         Sound:SetSoundVolume(self.RocketEngineLoop, 50);
  215.         Sound:PlaySound(self.RocketEngineLoop);
  216.     end
  217. end
  218.  
  219. ----------------------------------
  220. function SmokeRocket:Server_OnCollision( hit )
  221. end
  222.  
  223. function SmokeRocket:Client_OnCollision()
  224.     
  225. end
  226.  
  227. SmokeRocket.Server = {
  228.     OnInit = SmokeRocket.Server_OnInit,
  229.     OnCollision = SmokeRocket.Server_OnCollision,
  230.     Flying = {
  231.         OnBeginState = function(self)
  232.         end,
  233.         OnEndState = function(self)
  234.         end,
  235.         OnUpdate = SmokeRocket.Server_Flying_OnUpdate,
  236.     },
  237.     Exploding = {
  238.         OnBeginState = function(self)
  239.         end,
  240.         OnEndState = function(self)
  241.         end,
  242.         OnUpdate = SmokeRocket.Server_Exploding_OnUpdate,
  243.     },
  244. }
  245.  
  246. SmokeRocket.Client = {
  247.     OnInit = SmokeRocket.Client_OnInit,
  248.     OnCollision = SmokeRocket.Client_OnCollision,
  249.     Flying = {
  250.         OnBeginState = function(self)
  251.         end,
  252.         OnEndState = function(self)
  253.         end,
  254.         OnUpdate = SmokeRocket.Client_Flying_OnUpdate,
  255.     },
  256.     Exploding = {
  257.         OnBeginState = function(self)
  258.             self.Client_OnCollision( self );
  259.         end,
  260.         OnEndState = function(self)
  261.         end,
  262.         OnUpdate = SmokeRocket.Client_Exploding_OnUpdate,
  263.     },
  264. }